package com.leyou.pojo.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SkuDTO extends BaseDTO {

    private Long id;
    private Long spuId;
    private String title;
    private String images;
    private Integer stock;
    private Long price;
    private String indexes;
    private Long sold;
    private String special_spec;
    private Boolean saleable;//上下架



    /**
     * 将Entity对象转换为CategoryDTO对象
     * @param baseEntity
     */
    public SkuDTO(BaseEntity baseEntity){
        super(baseEntity);
    }

    /**
     * 将po集合转换为dto集合
     * @param list po集合
     * @param <T> po的类型
     * @return dto的集合
     */
    public static <T extends BaseEntity> List<SkuDTO> convertEntityList(Collection<T> list) {
        if (list == null && list.size()<0) {
            return Collections.emptyList();
        }
//        List<BrandDTO> listDTO = new ArrayList<>();
//        for (T t : list) {
//            BrandDTO categoryDTO = new BrandDTO(t);
//            listDTO.add(categoryDTO);
//        }
//
//        return listDTO;
        return list.stream().map(SkuDTO::new).collect(Collectors.toList());
    }
}
